package com.yexiao.cofe.business.controller;

import com.alibaba.fastjson2.JSONObject;
import com.yexiao.cofe.business.service.UserService;
import com.yexiao.cofe.resolver.IRequestParam;
import com.yexiao.cofe.resolver.IRequestToken;
import com.yexiao.core.response.ResponseData;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 控制用户行为
 */
@RestController
@RequestMapping("/user")
public class UserController{

    @Resource
    private UserService userService;

    @PostMapping("/login")
    public ResponseData login(@RequestBody JSONObject param) {
        return ResponseData.success(userService.login(param));
    }

    @PostMapping("/edit")
    public ResponseData editUserMsg(@RequestBody JSONObject param, @IRequestToken String token) {
        userService.editUserMsg(param, token);
        return ResponseData.success();
    }

    @GetMapping("/current")
    public ResponseData getCurrentUserMsg(@IRequestToken String token) {
        return ResponseData.success(userService.getCurrentUser(token));
    }

    @PostMapping("/bindRole")
    public ResponseData bindRole(@RequestBody JSONObject param, @IRequestToken String token) {
        userService.bindRole(param, token);
        return ResponseData.success();
    }

    @GetMapping("/listRole")
    public ResponseData listRole(@IRequestParam JSONObject param, @IRequestToken String token) {
        return ResponseData.success(userService.listRole(param, token));
    }
}
